﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.Profile;
using System.Text;
using System.Collections.Generic;
using HRProject.Code.Common;

namespace HRProject.Code.DTO
{
    public class BLUser : MembershipUser
    {
        private ProfileBase profile;

        public string FullName
        {
            get
            {
                return (string)profile.GetPropertyValue("FullName");
            }
            set
            {
                profile.SetPropertyValue("FullName", value);
            }
        }

        public string Phone
        {
            get
            {
                return (string)profile.GetPropertyValue("Phone");
            }
            set
            {
                profile.SetPropertyValue("Phone", value);
            }
        }

        public string Contact
        {
            get
            {
                return (string)profile.GetPropertyValue("Contact");
            }
            set
            {
                profile.SetPropertyValue("Contact", value);
            }
        }

        public DateTime BirthDate
        {
            get
            {
                return (DateTime)profile.GetPropertyValue("BirthDate");
            }
            set
            {
                profile.SetPropertyValue("BirthDate", value);
            }
        }

        public string BirthPlace
        {
            get
            {
                return (string)profile.GetPropertyValue("BirthPlace");
            }
            set
            {
                profile.SetPropertyValue("BirthPlace", value);
            }
        }

        public string Address
        {
            get
            {
                return (string)profile.GetPropertyValue("Address");
            }
            set
            {
                profile.SetPropertyValue("Address", value);
            }
        }

        public string IdentifiedSerial
        {
            get
            {
                return (string)profile.GetPropertyValue("IdentifiedSerial");
            }
            set
            {
                profile.SetPropertyValue("IdentifiedSerial", value);
            }
        }

        public int Gender
        {
            get
            {
                return (int)profile.GetPropertyValue("Gender");
            }
            set
            {
                profile.SetPropertyValue("Gender", value);
            }
        }

        public string People
        {
            get
            {
                return (string)profile.GetPropertyValue("People");
            }
            set
            {
                profile.SetPropertyValue("People", value);
            }
        }

        public string Assets
        {
            get
            {
                return (string)profile.GetPropertyValue("Assets");
            }
            set
            {
                profile.SetPropertyValue("Assets", value);
            }
        }

        public string ImageUrl
        {
            get
            {
                return (string)profile.GetPropertyValue("ImageUrl");
            }
            set
            {
                profile.SetPropertyValue("ImageUrl", value);
            }
        }

        public string ExtraDescription
        {
            get
            {
                return (string)profile.GetPropertyValue("ExtraDescription");
            }
            set
            {
                profile.SetPropertyValue("ExtraDescription", value);
            }
        }

        public string MaritalStatus
        {
            get
            {
                return (string)profile.GetPropertyValue("MaritalStatus");
            }
            set
            {
                profile.SetPropertyValue("MaritalStatus", value);
            }
        }

        public string ExtraContact
        {
            get
            {
                return (string)profile.GetPropertyValue("ExtraContact");
            }
            set
            {
                profile.SetPropertyValue("ExtraContact", value);
            }
        }

        public BLUser(MembershipUser user) : base
             (  user.ProviderName,
                user.UserName,
                user.ProviderUserKey,
                user.Email,
                user.PasswordQuestion,
                user.Comment,
                user.IsApproved,
                user.IsLockedOut,
                user.CreationDate,
                user.LastLoginDate,
                user.LastActivityDate,
                user.LastPasswordChangedDate,
                user.LastLockoutDate)
        {
            profile = ProfileBase.Create(this.UserName);
        }

        public string AccountStatus
        {
            get
            {
                StringBuilder result = new StringBuilder(ContentProvider.GetFormat("AccountStatus"));
                result.Replace("{I0}", BLAccountStatus.GetLockStatusCssClassName(IsLockedOut));
                result.Replace("{I1}", BLAccountStatus.GetLockStatusName(IsLockedOut));
                result.Replace("{I2}", BLAccountStatus.GetApproveStatusCssClassName(IsApproved));
                result.Replace("{I3}", BLAccountStatus.GetApproveStatusName(IsApproved));
                return result.ToString();
            }
        }

        public string HumanInformation
        {
            get
            {
                StringBuilder result = new StringBuilder(ContentProvider.GetFormat("HumanInformation"));
                result.Replace("{L0}", ContentProvider.GetString("FullName"));
                result.Replace("{L1}", ContentProvider.GetString("IdentifiedSerial"));
                result.Replace("{L2}", ContentProvider.GetString("BirthDate"));
                result.Replace("{L3}", ContentProvider.GetString("BirthPlace"));
                result.Replace("{I0}", FullName);
                result.Replace("{I1}", IdentifiedSerial);
                result.Replace("{I2}", BirthDate.ToString());
                result.Replace("{I3}", BirthPlace);
                return result.ToString();
            }
        }

        public string PeopleInformation
        {
            get
            {
                StringBuilder result = new StringBuilder(ContentProvider.GetFormat("PeopleInformation"));
                result.Replace("{L0}", ContentProvider.GetString("Gender"));
                result.Replace("{L1}", ContentProvider.GetString("People"));
                result.Replace("{L2}", ContentProvider.GetString("Address"));
                result.Replace("{I0}", BLGender.GetName(Gender));
                result.Replace("{I1}", People);
                result.Replace("{I2}", Address);
                return result.ToString();
            }
        }

        public string AccountInformation
        {
            get
            {
                StringBuilder result = new StringBuilder(ContentProvider.GetFormat("AccountInformation"));
                result.Replace("{L0}", ContentProvider.GetString("UserName"));
                result.Replace("{L1}", ContentProvider.GetString("Email"));
                result.Replace("{L2}", ContentProvider.GetString("Contact"));
                result.Replace("{I0}", UserName);
                result.Replace("{I1}", Email);
                result.Replace("{I2}", Contact);
                result.Replace("{I3}", ProviderUserKey.ToString());
                return result.ToString();
            }
        }

        public string TimeProperties
        {
            get
            {
                StringBuilder result = new StringBuilder(ContentProvider.GetFormat("TimeProperties"));
                result.Replace("{L0}", ContentProvider.GetString("CreationDate"));
                result.Replace("{L1}", ContentProvider.GetString("LastLoginDate"));
                result.Replace("{L2}", ContentProvider.GetString("LastActivityDate"));
                result.Replace("{I0}", CreationDate.ToString("dd/MM/yyyy-HH:mm"));
                result.Replace("{I1}", LastLoginDate.ToString("dd/MM/yyyy-HH:mm"));
                result.Replace("{I2}", LastActivityDate.ToString("dd/MM/yyyy-HH:mm"));
                return result.ToString();
            }
        }

        public void SaveProfile()
        {
            profile.Save();
        }
    }
}
